package com.qf.java2201.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.java2201.common.PageVo;
import com.qf.java2201.common.R;
import com.qf.java2201.mapper.DoorMapper;
import com.qf.java2201.pojo.Door;
import com.qf.java2201.service.DoorService;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("doorService")
public class DoorServiceImpl implements DoorService {

    @Autowired
    private DoorMapper doorMapper;

    @Override
    public PageVo<Door> getPageData(Map<String, Object> params) {

        String page = (String) params.get("page");
        String limit = (String) params.get("limit");
        //mybatis
        PageHelper.startPage(Integer.parseInt(page),Integer.parseInt(limit));

        List<Door> doors = doorMapper.selectByParams(params);

        PageInfo<Door> doorPageInfo = new PageInfo<>(doors);

        // 把分页数据 封装到 PageVo      这个 PageVo  符合 layui 的  列表数据格式
        PageVo<Door> doorPageVo = new PageVo<>();
        doorPageVo.setData(doorPageInfo.getList());
        doorPageVo.setCode(0);
        doorPageVo.setCount(doorPageInfo.getTotal());
        doorPageVo.setMsg("门店列表数据");
        return doorPageVo;
    }

    @Override
    public int addDoor(Door door) {

        return doorMapper.addDoor(door);
    }

    @Override
    public int deleteById(Integer id) {
        return doorMapper.deleteById(id);
    }

    @Override
    public int updateDoor(Door door) {

        return doorMapper.updateDoor(door);
    }

    @Override
    public List<Door> selectList(Door door) {
        return doorMapper.selectList(door);
    }

    @Override
    public void addDoors(List<Door> doors) {
        doorMapper.addDoors(doors);
    }

}
